'use strict';

/**
 * @ngdoc directive
 * @name jgappApp.directive:telDirective
 * @description
 * # telDirective
 */
angular.module('jgappApp')
    .directive('telDirective', ["$parse", function($parse) {
        return {
            require: 'ngModel',
            restrict: 'AE',
            link: function postLink(scope, element, attrs, ngModelController) {
                var reg = /^(([1-9]+\.?)|0)\d*$/i;
                // element.bind("input", function() {
                //     if (!reg.test(this.value)) {
                //         this.value = parseFloat(this.value) || ""
                //     }
                // })
                element.bind("blur", function() {
                    // if (!reg.test(this.value)) {
                    var data = parseFloat(this.value, 10) || ""
                    var modelGetter = $parse(attrs['ngModel']);
                    console.log(modelGetter(scope));
                    // This returns a function that lets us set the value of the ng-model binding expression:
                    var modelSetter = modelGetter.assign;
                    // This is how you can use it to set the value 'bar' on the given scope.
                    modelSetter(scope, data);
                    scope.$apply();
                    // }
                });
            }
        };
    }]);
